<template>
  <l-layout class="l-tab-page" v-loading="moduleLoading">
    <l-panel>
      <template #toolLeft>
        <div class="l-panel--item">
          <l-select
            v-model="appType"
            :placeholder="$t('请选择')"
            :options="[
              { value: '1', label: 'PC功能' },
              { value: '2', label: '移动功能' },
            ]"
            size="mini"
            :clearable="false"
            @change="handleChangeType"
          >
          </l-select>
        </div>
      </template>
      <div class="l-auto-window" style="padding: 0 8px">
        <el-tabs v-model="tabsActiveName" :before-leave="handleTabLeave">
          <el-tab-pane :label="$t('功能')" name="tabModule">
            <l-layout :bottom="40">
              <div class="l-rblock" style="overflow: auto">
                <el-tree
                  ref="modulesTree"
                  :data="modulesTree"
                  show-checkbox
                  default-expand-all
                  node-key="value"
                  @check="handleModuleCheck"
                >
                  <span class="lr-tree-node" slot-scope="{ data }">
                    {{ $t(data.label) }}
                  </span>
                </el-tree>
              </div>
              <template #bottom>
                <div class="l-rblock" style="text-align: right">
                  <el-button
                    @click="handleModuleCancel"
                    :disabled="!isSaveModule"
                    size="mini"
                    >取消</el-button
                  >
                  <el-button
                    @click="handleModuleSave"
                    :disabled="!isSaveModule"
                    size="mini"
                    type="primary"
                    >{{ $t('保存') }}</el-button
                  >
                </div>
              </template>
            </l-layout>
          </el-tab-pane>
          <el-tab-pane :label="$t('按钮')" name="tabButton">
            <l-layout :left="240" :bottom="40">
              <div class="l-rblock" style="overflow: auto">
                <el-tree
                  ref="buttonTree"
                  :data="buttonTree"
                  show-checkbox
                  default-expand-all
                  node-key="value"
                  @check="handleButtonCheck"
                >
                  <span class="lr-tree-node" slot-scope="{ data }">
                    {{ $t(data.label) }}
                  </span>
                </el-tree>
              </div>
              <template #left>
                <div
                  class="l-rblock"
                  style="overflow: auto; border-right: 1px solid #e4e7ed"
                >
                  <el-tree
                    :data="myModulesTree"
                    default-expand-all
                    node-key="value"
                    @node-click="handleModuleClick"
                  >
                    <span class="lr-tree-node" slot-scope="{ data }">
                      {{ $t(data.label) }}
                    </span>
                  </el-tree>
                </div>
              </template>
              <template #bottom>
                <div class="l-rblock" style="text-align: right">
                  <el-button
                    @click="handleButtonCancel"
                    :disabled="!isSaveButton"
                    size="mini"
                    >{{ $t('取消') }}</el-button
                  >
                  <el-button
                    @click="handleButtonSave"
                    :disabled="!isSaveButton"
                    size="mini"
                    type="primary"
                    >{{ $t('保存') }}</el-button
                  >
                </div>
              </template>
            </l-layout>
          </el-tab-pane>
          <el-tab-pane :label="$t('列表')" name="tabCol">
            <l-layout :left="240" :bottom="40">
              <div class="l-rblock" style="overflow: auto">
                <el-tree
                  ref="columnTree"
                  :data="columnTree"
                  show-checkbox
                  default-expand-all
                  node-key="value"
                  @check="handleColumnCheck"
                >
                  <span class="lr-tree-node" slot-scope="{ data }">
                    {{ $t(data.label) }}
                  </span>
                </el-tree>
              </div>
              <template #left>
                <div
                  class="l-rblock"
                  style="overflow: auto; border-right: 1px solid #e4e7ed"
                >
                  <el-tree
                    :data="myModulesTree"
                    default-expand-all
                    node-key="value"
                    @node-click="handleColModuleClick"
                  >
                    <span class="lr-tree-node" slot-scope="{ data }">
                      {{ $t(data.label) }}
                    </span>
                  </el-tree>
                </div>
              </template>
              <template #bottom>
                <div class="l-rblock" style="text-align: right">
                  <el-button
                    @click="handleColumnCancel"
                    :disabled="!isSaveColumn"
                    size="mini"
                    >{{ $t('取消') }}</el-button
                  >
                  <el-button
                    @click="handleColumnSave"
                    :disabled="!isSaveColumn"
                    size="mini"
                    type="primary"
                    >{{ $t('保存') }}</el-button
                  >
                </div>
              </template>
            </l-layout>
          </el-tab-pane>
          <el-tab-pane :label="$t('表单')" name="tabForm">
            <l-layout :left="240" :bottom="40">
              <div class="l-rblock" style="overflow: auto">
                <el-tree
                  ref="formTree"
                  :data="formTree"
                  show-checkbox
                  default-expand-all
                  node-key="value"
                  @check="handleFormCheck"
                >
                  <span class="lr-tree-node" slot-scope="{ data }">
                    {{ $t(data.label) }}
                  </span>
                </el-tree>
              </div>
              <template #left>
                <div
                  class="l-rblock"
                  style="overflow: auto; border-right: 1px solid #e4e7ed"
                >
                  <el-tree
                    :data="myModulesTree"
                    default-expand-all
                    node-key="value"
                    @node-click="handleFormModuleClick"
                  >
                    <span class="lr-tree-node" slot-scope="{ data }">
                      {{ $t(data.label) }}
                    </span>
                  </el-tree>
                </div>
              </template>
              <template #bottom>
                <div class="l-rblock" style="text-align: right">
                  <el-button
                    @click="handleFormCancel"
                    :disabled="!isSaveForm"
                    size="mini"
                    >{{ $t('取消') }}</el-button
                  >
                  <el-button
                    @click="handleFormSave"
                    :disabled="!isSaveForm"
                    size="mini"
                    type="primary"
                    >{{ $t('保存') }}</el-button
                  >
                </div>
              </template>
            </l-layout>
          </el-tab-pane>
        </el-tabs>
      </div>
    </l-panel>
  </l-layout>
</template>

<script>
import { mapGetters } from "vuex";
const api = window.$api.sass.auth;
const apiModule = window.$api.system.module;

const apiAppModule = window.$api.mapp.module;

export default {
  data() {
    return {
      tabsActiveName: "tabModule",
      id: "", // 租户组id
      appType: "1", // 应用类型

      // 功能
      moduleLoading: false,
      moduleAuthList: [],
      moduleChecked: [],

      moduleId: "",

      apps: [],

      // 按钮
      buttons: [],
      buttonList: [],
      buttonChecked: [],

      // 列表
      columns: [],
      columnList: [],
      columnChecked: [],

      // 表
      forms: [],
      formList: [],
      formChecked: [],
    };
  },
  computed: {
    ...mapGetters(["modules"]),

    // 功能模块
    myModules() {
      return this.modules.filter(
        (t) => t.f_EnabledMark == 1 && t.f_EnCode.indexOf("sass_") != 0
      );
    },
    modulesTree() {
      if (this.appType == "1") {
        const res = this.$toTree(
          this.myModules,
          "f_ModuleId",
          "f_ParentId",
          "f_ModuleId",
          "f_FullName"
        );
        return res.filter((t) => t.f_ParentId == "0");
      } else {
        return this.getAppTree(this.apps);
      }
    },
    myModulesTree() {
      if (this.appType == "1") {
        const list = this.myModules.filter(
          (t) => this.moduleAuthList.indexOf(t.f_ModuleId) > -1
        );
        return this.$toTree(
          list,
          "f_ModuleId",
          "f_ParentId",
          "f_ModuleId",
          "f_FullName"
        );
      } else {
        const list = this.apps.filter(
          (t) =>
            t.f_IsSystem != 3 &&
            t.f_IsSystem != 4 &&
            this.moduleAuthList.indexOf(t.f_Id) > -1
        );
        return this.getAppTree(list);
      }
    },
    isSaveModule() {
      return !this.equalsArr(this.moduleAuthList, this.moduleChecked);
    },

    // 按钮
    buttonTree() {
      let list = this.buttons;
      const res =
        this.appType == "1"
          ? this.$toTree(
              list,
              "f_Id",
              "f_ParentId",
              "f_EnCode",
              "f_FullName"
            )
          : this.$toTree(list, "f_Id", "f_ParentId", "f_Code", "f_Name");
      return res;
    },
    isSaveButton() {
      return !this.equalsArr(this.buttonList, this.buttonChecked);
    },

    // 列表
    columnTree() {
      let list = this.columns;
      const res =
        this.appType == "1"
          ? this.$toTree(
              list,
              "f_Id",
              "f_ParentId",
              "f_EnCode",
              "f_FullName"
            )
          : this.$toTree(list, "f_Id", "f_ParentId", "f_Code", "f_Name");
      return res;
    },
    isSaveColumn() {
      return !this.equalsArr(this.columnList, this.columnChecked);
    },

    // 表单
    formTree() {
      let list = this.forms;
      const res =
        this.appType == "1"
          ? this.$toTree(
              list,
              "f_Id",
              "f_ParentId",
              "f_EnCode",
              "f_FullName"
            )
          : this.$toTree(list, "f_Id", "f_ParentId", "f_Code", "f_Name");
      return res;
    },
    isSaveForm() {
      return !this.equalsArr(this.formList, this.formChecked);
    },
  },
  methods: {
    equalsArr(arr1, arr2) {
      let flag = true;
      if (arr1.length !== arr2.length) {
        flag = false;
      } else {
        arr1.forEach((item) => {
          if (arr2.indexOf(item) === -1) {
            flag = false;
          }
        });

        arr2.forEach((item) => {
          if (arr1.indexOf(item) === -1) {
            flag = false;
          }
        });
      }
      return flag;
    },

    async init(id) {
      this.id = id;
      await this.fetchModuleAuthData(id);
    },
    async close() {
      await this.handleTabLeave();
      this.tabsActiveName = "tabModule";
      this.appType = "1";
    },

    async handleTabLeave() {
      switch (this.tabsActiveName) {
        case "tabModule":
          await this.leaveModule();
          break;
        case "tabButton":
          await this.leaveButton();
          break;
        case "tabCol":
          await this.leaveColumn();
          break;
        case "tabForm":
          await this.leaveForm();
          break;
      }
    },

    // 功能模块
    async fetchModuleAuthData(id) {
      this.moduleChecked = [];
      this.moduleAuthList = [];

      if (this.appType == "1") {
        this.moduleAuthList = (
          await this.$awaitWraper(api.getList(id, 1, "0"))
        ).map((t) => t.f_ItemId); // 加载功能模块权限

        var x = this.moduleAuthList.find(t=>t == '87df6e42-fd64-4f46-bc06-74b26a8634bc')

        console.log(x,'test')

      } else {
        await this.lr_loadDataItem("function");
        this.apps = await this.$awaitWraper(apiAppModule.getList());
        this.moduleAuthList = (
          await this.$awaitWraper(api.getList(id, 5, "0"))
        ).map((t) => t.f_ItemId); // 加载功能模块权限
      }

      this.$nextTick(() => {
        this.$refs.modulesTree.setCheckedKeys(
          this.moduleAuthList.filter(
            (t) => this.myModules.findIndex((t2) => t2.f_ParentId == t) == -1
          )
        );

        const checkedKeys = this.$refs.modulesTree.getCheckedKeys();
        const halfCheckedKeys = this.$refs.modulesTree.getHalfCheckedKeys();
        this.moduleChecked = checkedKeys.concat(halfCheckedKeys);
      });
    },
    handleModuleCheck(node, data) {
      this.moduleChecked = data.checkedKeys.concat(data.halfCheckedKeys);
    },
    handleModuleCancel() {
      this.moduleChecked = this.$deepClone(this.moduleAuthList);
      this.$refs.modulesTree.setCheckedKeys(this.moduleChecked);
    },
    async handleModuleSave() {
      this.moduleLoading = true;
      const data = {
        ids: this.moduleChecked,
        itemType: this.appType == "1" ? 1 : 5,
        parentId: "0",
      };
      const res = await this.$awaitWraper(api.save(this.id, data));
      if (res) {
        this.$message({
          type: "success",
          message: this.$t("保存成功!"),
        });
        this.moduleAuthList = this.$deepClone(this.moduleChecked);
      }

      this.moduleLoading = false;
    },

    leaveModule() {
      return new Promise((resolve) => {
        if (this.isSaveModule) {
          this.$confirm(this.$t("离开前,是否保存设置数据?"), this.$t("提示"), {
            confirmButtonText: this.$t("确定"),
            cancelButtonText: this.$t("取消"),
            type: "warning",
          })
            .then(async () => {
              await this.handleModuleSave();
              resolve();
            })
            .catch(() => {
              this.$nextTick(() => {
                this.$refs.modulesTree.setCheckedKeys(
                  this.moduleAuthList.filter(
                    (t) =>
                      this.myModules.findIndex((t2) => t2.f_ParentId == t) == -1
                  )
                );

                const checkedKeys = this.$refs.modulesTree.getCheckedKeys();
                const halfCheckedKeys =
                  this.$refs.modulesTree.getHalfCheckedKeys();
                this.moduleChecked = checkedKeys.concat(halfCheckedKeys);
                resolve();
              });
            });
        } else {
          resolve();
        }
      });
    },

    // 获取移动功能树形数据
    getAppTree(list) {
      if (list.length == 0) {
        return [];
      }
      const map = {};
      const res = [];
      const dataItemList = this.lr_dataItem["function"] || [];
      dataItemList.forEach((item) => {
        let point = {
          label: item.f_ItemName,
          value: item.f_ItemValue,
          children: [],
        };
        map[item.f_ItemValue] = point.children;
        res.push(point);
      });
      list.forEach((item) => {
        item.label = item.f_Name;
        item.value = item.f_Id;
        if (!map[item.f_Type]) {
          // 解决部分功能分类数据被删除
          let point = {
            label: item.f_Type,
            value: item.f_Type,
            children: [],
          };
          map[item.f_Type] = point.children;
          res.push(point);
        }
        map[item.f_Type].push(item);
      });
      return res.filter((t) => t.children.length > 0);
    },

    // 按钮
    async handleModuleClick(data) {
      if (this.moduleId == data.value) {
        return;
      }
      await this.leaveButton();
      this.moduleId = data.value;
      if (data.f_Target == "expand") {
        this.buttons = [];
        this.buttonList = [];
        this.buttonChecked = [];
      } else {
        this.moduleLoading = true;
        if (this.appType == "1") {
          await this.fetchButtons(this.moduleId, data.f_FullName);
        } else {
          await this.fetchAppButtons(this.moduleId, data.f_Name);
        }

        this.moduleLoading = false;
      }
    },
    async fetchButtons(moduleId, moduleName) {
      const point = {
        f_Id: "0",
        f_ParentId: "01",
        f_EnCode: "0",
        f_FullName: moduleName,
      };
      if (moduleId == "7ae94059-9aa5-48eb-8330-4e2a6565b193") {
        this.buttons = [];
        this.buttonList = [];
        this.$refs.buttonTree.setCheckedKeys(this.buttonList);
        return;
      }

      const buttonList = await this.$awaitWraper(
        apiModule.getButtons(moduleId)
      );
      buttonList.forEach((t) => (t.f_ParentId = "0"));
      if (buttonList.length > 0) {
        buttonList.push(point);
      }

      await this.fetchAuthButtons(moduleId);
      this.buttons = buttonList;
      this.$refs.buttonTree.setCheckedKeys(this.buttonList);
    },
    async fetchAppButtons(moduleId, moduleName) {
      const point = {
        f_Id: "0",
        f_ParentId: "01",
        f_Code: "0",
        f_Name: moduleName,
      };
      const buttonList = await this.$awaitWraper(
        apiAppModule.getChildren(moduleId, 1)
      );
      buttonList.forEach((t) => (t.f_ParentId = "0"));
      if (buttonList.length > 0) {
        buttonList.push(point);
      }

      await this.fetchAuthButtons(moduleId);
      this.buttons = buttonList;
      this.$refs.buttonTree.setCheckedKeys(this.buttonList);
    },
    async fetchAuthButtons(moduleId) {
      const res = await this.$awaitWraper(
        api.getList(this.id, this.appType == "1" ? 2 : 6, moduleId)
      );
      this.buttonList = res.map((t) => t.f_ItemId);
      this.buttonChecked = this.$deepClone(this.buttonList);
    },
    handleButtonCheck(node, data) {
      this.buttonChecked = data.checkedKeys
        .concat(data.halfCheckedKeys)
        .filter((t) => t != "0");
    },
    handleButtonCancel() {
      this.buttonChecked = this.$deepClone(this.buttonList);
      this.$refs.buttonTree.setCheckedKeys(this.buttonChecked);
    },
    async handleButtonSave() {
      this.moduleLoading = true;
      const data = {
        ids: this.buttonChecked,
        itemType: this.appType == "1" ? 2 : 6,
        parentId: this.moduleId,
      };
      const res = await this.$awaitWraper(api.save(this.id, data));
      if (res) {
        this.$message({
          type: "success",
          message: this.$t("保存成功!"),
        });
        this.buttonList = this.$deepClone(this.buttonChecked);
      }

      this.moduleLoading = false;
    },
    leaveButton() {
      return new Promise((resolve) => {
        if (this.isSaveButton) {
          this.$confirm(this.$t("离开前,是否保存设置数据?"), this.$t("提示"), {
            confirmButtonText: this.$t("确定"),
            cancelButtonText: this.$t("取消"),
            type: "warning",
          })
            .then(async () => {
              await this.handleButtonSave();
              this.buttonList = [];
              this.buttonChecked = [];
              this.buttons = [];
              this.moduleId = "";
              resolve();
            })
            .catch(() => {
              this.buttonList = [];
              this.buttonChecked = [];
              this.buttons = [];
              this.moduleId = "";
              resolve();
            });
        } else {
          this.buttonList = [];
          this.buttonChecked = [];
          this.buttons = [];
          this.moduleId = "";
          resolve();
        }
      });
    },

    // 列表
    async handleColModuleClick(data) {
      if (this.moduleId == data.value) {
        return;
      }
      await this.leaveColumn();
      this.moduleId = data.value;
      if (data.f_Target == "expand") {
        this.columns = [];
        this.columnList = [];
        this.columnChecked = [];
      } else {
        this.moduleLoading = true;
        if (this.appType == "1") {
          await this.fetchColumns(this.moduleId, data.f_FullName);
        } else {
          await this.fetchAppColumns(this.moduleId, data.f_Name);
        }

        this.moduleLoading = false;
      }
    },
    async fetchColumns(moduleId, moduleName) {
      const point = {
        f_Id: "0",
        f_ParentId: "01",
        f_EnCode: "0",
        f_FullName: moduleName,
      };
      if (moduleId == "7ae94059-9aa5-48eb-8330-4e2a6565b193") {
        this.columns = [];
        this.columnList = [];
        this.$refs.columnTree.setCheckedKeys(this.columnList);
        return;
      }

      const columns = await this.$awaitWraper(apiModule.getColumns(moduleId));
      columns.forEach((t) => (t.f_ParentId = "0"));
      if (columns.length > 0) {
        columns.push(point);
      }

      await this.fetchAuthColumns(moduleId);
      this.columns = columns;
      this.$refs.columnTree.setCheckedKeys(this.columnList);
    },
    async fetchAppColumns(moduleId, moduleName) {
      const point = {
        f_Id: "0",
        f_ParentId: "01",
        f_Code: "0",
        f_Name: moduleName,
      };
      const columns = await this.$awaitWraper(
        apiAppModule.getChildren(moduleId, 2)
      );
      columns.forEach((t) => (t.f_ParentId = "0"));
      if (columns.length > 0) {
        columns.push(point);
      }

      await this.fetchAuthColumns(moduleId);
      this.columns = columns;
      this.$refs.columnTree.setCheckedKeys(this.columnList);
    },
    async fetchAuthColumns(moduleId) {
      const res = await this.$awaitWraper(
        api.getList(this.id, this.appType == "1" ? 3 : 7, moduleId)
      );
      this.columnList = res.map((t) => t.f_ItemId);
      this.columnChecked = this.$deepClone(this.columnList);
    },

    handleColumnCheck(node, data) {
      this.columnChecked = data.checkedKeys
        .concat(data.halfCheckedKeys)
        .filter((t) => t != "0");
    },
    handleColumnCancel() {
      this.columnChecked = this.$deepClone(this.columnList);
      this.$refs.columnTree.setCheckedKeys(this.columnChecked);
    },
    async handleColumnSave() {
      this.moduleLoading = true;
      const data = {
        ids: this.columnChecked,
        itemType: this.appType == "1" ? 3 : 7,
        parentId: this.moduleId,
      };
      const res = await this.$awaitWraper(api.save(this.id, data));
      if (res) {
        this.$message({
          type: "success",
          message: this.$t("保存成功!"),
        });
        this.columnList = this.$deepClone(this.columnChecked);
      }

      this.moduleLoading = false;
    },
    leaveColumn() {
      return new Promise((resolve) => {
        if (this.isSaveColumn) {
          this.$confirm(this.$t("离开前,是否保存设置数据?"), this.$t("提示"), {
            confirmButtonText: this.$t("确定"),
            cancelButtonText: this.$t("取消"),
            type: "warning",
          })
            .then(async () => {
              await this.handleColumnSave();
              this.columnList = [];
              this.columnChecked = [];
              this.columns = [];
              this.moduleId = "";
              resolve();
            })
            .catch(() => {
              this.columnList = [];
              this.columnChecked = [];
              this.columns = [];
              this.moduleId = "";
              resolve();
            });
        } else {
          this.columnList = [];
          this.columnChecked = [];
          this.columns = [];
          this.moduleId = "";
          resolve();
        }
      });
    },

    // 表单
    async handleFormModuleClick(data) {
      if (this.moduleId == data.value) {
        return;
      }
      await this.leaveForm();
      this.moduleId = data.value;
      if (data.f_Target == "expand") {
        this.forms = [];
        this.formList = [];
        this.formChecked = [];
      } else {
        this.moduleLoading = true;
        if (this.appType == "1") {
          await this.fetchForms(this.moduleId, data.f_FullName);
        } else {
          await this.fetchAppForms(this.moduleId, data.f_Name);
        }
        this.moduleLoading = false;
      }
    },
    async fetchForms(moduleId, moduleName) {
      const point = {
        f_Id: "0",
        f_ParentId: "01",
        f_EnCode: "0",
        f_FullName: moduleName,
      };
      const forms = await this.$awaitWraper(apiModule.getForms(moduleId));
      forms.forEach((t) => (t.f_ParentId = "0"));
      if (forms.length > 0) {
        forms.push(point);
      }

      await this.fetchAuthForms(moduleId);
      this.forms = forms;
      this.$refs.formTree.setCheckedKeys(this.formList);
    },
    async fetchAppForms(moduleId, moduleName) {
      const point = {
        f_Id: "0",
        f_ParentId: "01",
        f_Code: "0",
        f_Name: moduleName,
      };
      const forms = await this.$awaitWraper(
        apiAppModule.getChildren(moduleId, 3)
      );
      forms.forEach((t) => (t.f_ParentId = "0"));
      if (forms.length > 0) {
        forms.push(point);
      }

      await this.fetchAuthForms(moduleId);
      this.forms = forms;
      this.$refs.formTree.setCheckedKeys(this.formList);
    },
    async fetchAuthForms(moduleId) {
      const res = await this.$awaitWraper(
        api.getList(this.id, this.appType == "1" ? 4 : 8, moduleId)
      );
      this.formList = res.map((t) => t.f_ItemId);
      this.formChecked = this.$deepClone(this.formList);
    },

    handleFormCheck(node, data) {
      this.formChecked = data.checkedKeys
        .concat(data.halfCheckedKeys)
        .filter((t) => t != "0");
    },
    handleFormCancel() {
      this.formChecked = this.$deepClone(this.formList);
      this.$refs.formTree.setCheckedKeys(this.formChecked);
    },
    async handleFormSave() {
      this.moduleLoading = true;
      const data = {
        ids: this.formChecked,
        itemType: this.appType == "1" ? 4 : 8,
        parentId: this.moduleId,
      };
      const res = await this.$awaitWraper(api.save(this.id, data));
      if (res) {
        this.$message({
          type: "success",
          message: this.$t("保存成功!"),
        });
        this.formList = this.$deepClone(this.formChecked);
      }

      this.moduleLoading = false;
    },
    leaveForm() {
      return new Promise((resolve) => {
        if (this.isSaveForm) {
          this.$confirm(this.$t("离开前,是否保存设置数据?"), this.$t("提示"), {
            confirmButtonText: this.$t("确定"),
            cancelButtonText: this.$t("取消"),
            type: "warning",
          })
            .then(async () => {
              await this.handleFormSave();
              this.formList = [];
              this.formChecked = [];
              this.forms = [];
              this.moduleId = "";
              resolve();
            })
            .catch(() => {
              this.formList = [];
              this.formChecked = [];
              this.forms = [];
              this.moduleId = "";
              resolve();
            });
        } else {
          this.formList = [];
          this.formChecked = [];
          this.forms = [];
          this.moduleId = "";
          resolve();
        }
      });
    },

    // 变更授权类型
    async handleChangeType() {
      await this.handleTabLeave();
      this.tabsActiveName = "tabModule";
      this.fetchModuleAuthData(this.id);
    },
  },
};
</script>